﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Kinect;
using BicycleTrafficSimulator.DataModel;
using System.Threading;

namespace BicycleTrafficSimulator
{
    public class TrafficSign : AbstractModel, IGameObject
    {
        public TrafficSign()
        {

        
        }
        public TrafficSign(Vector3 position, float rotation)
        {
            this.Position = position;
            this.Rotation = rotation;
            this.Scale = new Vector3(0.0006f, 0.0006f, 0.0006f);
        }

        public void LoadContent(ContentManager content, String modelName)
        {
            this.Model = content.Load<Model>(modelName);
        }

        public void Update(GameTime gameTime)
        {

        }

        public void Draw(Matrix viewMatrix, Matrix projectionMatrix)
        {
            // Copy any parent transforms.
            Matrix[] transforms = new Matrix[this.Model.Bones.Count];
          //  float aspectRatio = graphics.GraphicsDevice.Viewport.AspectRatio;
            this.Model.CopyAbsoluteBoneTransformsTo(transforms);

            // Draw the model. A model can have multiple meshes, so loop.
            foreach (ModelMesh mesh in this.Model.Meshes)
            {
                // This is where the mesh orientation is set, as well 
                // as our camera and projection.
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.EnableDefaultLighting();
                    effect.World = transforms[mesh.ParentBone.Index] *
                        Matrix.CreateScale(this.Scale.X, this.Scale.Y, this.Scale.Z) * Matrix.CreateRotationY(MathHelper.Pi) *
                        Matrix.CreateRotationY(this.Rotation)
                        * Matrix.CreateTranslation(this.Position);
                    effect.View = viewMatrix;
                  /*  effect.Projection = Matrix.CreatePerspectiveFieldOfView(
                        MathHelper.ToRadians(45.0f), aspectRatio,
                        1.0f, 10000.0f); */
                    effect.Projection = projectionMatrix;
                    effect.GraphicsDevice.BlendState = BlendState.Opaque;
                    effect.GraphicsDevice.DepthStencilState = DepthStencilState.Default;

                }
                // Draw the mesh, using the effects set above.
                mesh.Draw();
            }

        }

    }
}
